package com.yellowpage.bigdata.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yellowpage.white.common.Configuration;
import com.yellowpage.white.common.Constants;
import com.yellowpage.white.struts.BaseAction;
import com.yellowpage.white.struts.Module;
import com.yellowpage.white.struts.OperationType;
import com.yellowpage.white.util.Util4Java;

import com.yellowpage.bigdata.data.TmApponoffNewUserMonthEntity;
import com.yellowpage.bigdata.service.TmApponoffNewUserMonthEntityService;

public class TmApponoffNewUserMonthEntityAction extends BaseAction {

    public String RESULT_QUERY = "query";
    public String RESULT_ADD = "add";
    public String RESULT_EDIT = "edit";

    private Configuration configuration;

    public void setConfiguration(Configuration configuration) {
        this.configuration = configuration;
    }

    private List<TmApponoffNewUserMonthEntity> tmApponoffNewUserMonthEntityList = new ArrayList<TmApponoffNewUserMonthEntity>();
    private List<Map> resultList = new ArrayList<Map>();

    private TmApponoffNewUserMonthEntity tmApponoffNewUserMonthEntity;
    private TmApponoffNewUserMonthEntityService tmApponoffNewUserMonthEntityService;

    private String selectedId;
    private String[] selectedIds;
    private String message;

    private String query_tmApponoffNewUserMonthId;
    private String query_areacode;
    private String query_operator;
    private String query_channelno;
    private String query_uvImei;
    private String query_createTime;
    private String query_monthId;

    public void prepare() {
        super.prepare();

        if (this.selectedId != null && !this.selectedId.equals("")) {
            this.tmApponoffNewUserMonthEntity = tmApponoffNewUserMonthEntityService.getTmApponoffNewUserMonthEntity(Long.parseLong(selectedId));
        }
    }

    public String queryByPage() {
        initPageRender();

        Map queryMap = new HashMap();
        queryMap.put("tmApponoffNewUserMonthId", query_tmApponoffNewUserMonthId);
        queryMap.put("areacode", query_areacode);
        queryMap.put("operator", query_operator);
        queryMap.put("channelno", query_channelno);
        queryMap.put("uvImei", query_uvImei);
        queryMap.put("createTime", query_createTime);
        queryMap.put("monthId", query_monthId);

        resultList = tmApponoffNewUserMonthEntityService.queryTmApponoffNewUserMonthEntityByPage(queryMap, pageRender);

        setPageRenderToRequest();

        return RESULT_QUERY;
    }

    public String toAdd() {
        return RESULT_ADD;
    }

    public String save() {

        tmApponoffNewUserMonthEntityService.saveTmApponoffNewUserMonthEntity(tmApponoffNewUserMonthEntity);

        message = "新增成功!";
        return RESULT_ADD;
    }

    public void validateSave() {
        if (tmApponoffNewUserMonthEntity.getAreacode().length() == 0) {
            this.addActionError("** Areacode 不能为空 !");
        }
        if (tmApponoffNewUserMonthEntity.getOperator().length() == 0) {
            this.addActionError("** Operator 不能为空 !");
        }
        if (tmApponoffNewUserMonthEntity.getChannelno().length() == 0) {
            this.addActionError("** Channelno 不能为空 !");
        }
        if (tmApponoffNewUserMonthEntity.getMonthId().length() == 0) {
            this.addActionError("** MonthId 不能为空 !");
        }

        this.setValidatorResult("/bigdata/TmApponoffNewUserMonthEntityAdd.jsp");
    }

    public String toEdit() {
        Long id = new Long(selectedId);

        tmApponoffNewUserMonthEntity = tmApponoffNewUserMonthEntityService.getTmApponoffNewUserMonthEntity(id);

        return RESULT_EDIT;
    }

    public String update() {

        tmApponoffNewUserMonthEntityService.updateTmApponoffNewUserMonthEntity(tmApponoffNewUserMonthEntity);

        message = "修改成功!";

        return RESULT_EDIT;
    }

    public void validateUpdate() {
        if (tmApponoffNewUserMonthEntity.getAreacode().length() == 0) {
            this.addActionError("** Areacode 不能为空 !");
        }
        if (tmApponoffNewUserMonthEntity.getOperator().length() == 0) {
            this.addActionError("** Operator 不能为空 !");
        }
        if (tmApponoffNewUserMonthEntity.getChannelno().length() == 0) {
            this.addActionError("** Channelno 不能为空 !");
        }
        if (tmApponoffNewUserMonthEntity.getMonthId().length() == 0) {
            this.addActionError("** MonthId 不能为空 !");
        }
        this.setValidatorResult("/bigdata/TmApponoffNewUserMonthEntityUpdate.jsp");
    }

    public String delete() {
        List ids = new ArrayList();

        for (String id : selectedIds) {
            ids.add(Long.valueOf(id));
        }

        try {
            this.tmApponoffNewUserMonthEntityService.delete(ids);
        } catch (Exception e) {
            System.out.println("异常....");
            this.addActionError("** 可能含有子记录约束冲突,删除失败 !");
        }


        return queryByPage();
    }


    /**
     * getters and setters
     *
     * @return
     */
    public void setTmApponoffNewUserMonthEntity(TmApponoffNewUserMonthEntity tmApponoffNewUserMonthEntity) {
        this.tmApponoffNewUserMonthEntity = tmApponoffNewUserMonthEntity;
    }

    public TmApponoffNewUserMonthEntity getTmApponoffNewUserMonthEntity() {
        return tmApponoffNewUserMonthEntity;
    }


    public void setTmApponoffNewUserMonthEntityService(TmApponoffNewUserMonthEntityService tmApponoffNewUserMonthEntityService) {
        this.tmApponoffNewUserMonthEntityService = tmApponoffNewUserMonthEntityService;
    }

    public List<TmApponoffNewUserMonthEntity> getTmApponoffNewUserMonthEntityList() {
        return tmApponoffNewUserMonthEntityList;
    }

    public void setTmApponoffNewUserMonthEntityList(List<TmApponoffNewUserMonthEntity> tmApponoffNewUserMonthEntityList) {
        this.tmApponoffNewUserMonthEntityList = tmApponoffNewUserMonthEntityList;
    }

    public String getSelectedId() {
        return selectedId;
    }

    public void setSelectedId(String selectedId) {
        this.selectedId = selectedId;
    }

    public String[] getSelectedIds() {
        return selectedIds;
    }

    public void setSelectedIds(String[] selectedIds) {
        this.selectedIds = selectedIds;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public List<Map> getResultList() {
        return resultList;
    }

    public void setResultList(List<Map> resultList) {
        this.resultList = resultList;
    }

    public String getQuery_tmApponoffNewUserMonthId() {
        return this.query_tmApponoffNewUserMonthId;
    }

    public void setQuery_tmApponoffNewUserMonthId(String tmApponoffNewUserMonthId) {
        this.query_tmApponoffNewUserMonthId = tmApponoffNewUserMonthId;
    }

    public String getQuery_areacode() {
        return this.query_areacode;
    }

    public void setQuery_areacode(String areacode) {
        this.query_areacode = areacode;
    }

    public String getQuery_operator() {
        return this.query_operator;
    }

    public void setQuery_operator(String operator) {
        this.query_operator = operator;
    }

    public String getQuery_channelno() {
        return this.query_channelno;
    }

    public void setQuery_channelno(String channelno) {
        this.query_channelno = channelno;
    }

    public String getQuery_uvImei() {
        return this.query_uvImei;
    }

    public void setQuery_uvImei(String uvImei) {
        this.query_uvImei = uvImei;
    }

    public String getQuery_createTime() {
        return this.query_createTime;
    }

    public void setQuery_createTime(String createTime) {
        this.query_createTime = createTime;
    }

    public String getQuery_monthId() {
        return this.query_monthId;
    }

    public void setQuery_monthId(String monthId) {
        this.query_monthId = monthId;
    }


}
